import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vite.dev/config/
// 引入svg需要用到的插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
import { viteMockServe } from 'vite-plugin-mock'
export default defineConfig(({ command }) => {
  return {
    plugins: [vue(),
      viteMockServe({
        enable: command === 'serve'
      }),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
        symbolId: 'icon-[dir]-[name]', // 支持目录层级：'icon-[dir]-[name]'
        // inject: 'body-last',    // DOM插入位置
        // customDomId: '__svg_icons' // 自定义容器ID
      })
    ],
    
    resolve: {
      alias: {
        "@": path.resolve("./src") // 相对路径别名配置，使用@代替src
      }
    },
    // scss全局变量的配置
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          // additionalData: `@import "@/styles/variable.scss";`, // @import sass 语法弃用，改用@use
          additionalData: `@use "@/styles/variable.scss" as *;`,
        }
      }
    }
  }
})
